<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="lib/layui-v2.5.5/css/layui.css">
    <title>评价分析</title>
    <link rel="stylesheet" href="lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="css/public.css" media="all">
    <link rel="stylesheet" href="css/card.css">
</head>
<body>
<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label">开始月份</label>
                    <div class="layui-input-inline">
                        <input type="text" name="startTime" id="=startTime" class="layui-input datetime"
                               placeholder="(包含此月)" required lay-verify="required">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">终止月份</label>
                    <div class="layui-input-inline">
                        <input type="text" name="endTime" id="endTime" class="layui-input datetime"
                               placeholder="(不包含此月)" required lay-verify="required">
                    </div>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i
                            class="layui-icon">&#xe666;</i> 重载数据</a>
                </div>
                <label class=" layui-text">(初始数据默认一年内,不包括当前所在月份)</label>
            </form>
        </div>
        <div class="layui-card-body">
            <div class="layui-row layui-col-space15">
                <div class="layui-row layui-col-md8">
                    <!--echarts-->
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-header"><i class="fa fa-bar-chart icon"></i>客户评分直方图</div>
                            <div class="layui-card-body">
                                <div id="main" style="width: 100%;height:400px;"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-row ">
                        <div class="layui-col-xs6">
                            <div class="layui-card">
                                <div class="layui-card-header"><i class="fa fa-users icon"></i>公司对客户平均评分</div>
                                <div class="layui-card-body " style="color: rgb(102,102,102);">
                                    <h1 id="companyToCustomer">--</h1>
                                    <br/>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs6">
                            <div class="layui-card">
                                <div class="layui-card-header"><i class="fa fa-street-view icon"></i>客户对公司平均评分</div>
                                <div class="layui-card-body" style="color: rgb(102,102,102);">
                                    <h1 id="customerToCompany">--</h1>
                                    <br/><!-- <small>vip客户数：<span> 48%</span></small>-->
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-card">
                                <div class="layui-card-header"><i class="fa fa-long-arrow-up icon"></i>最近评分最高客户的评价</div>
                                <div class="layui-card-body">
                                    <div  style="width: 100%;min-height: 140px">
                                        评分：<h1 id="maxScore">--</h1>
                                        评价：<p id="maxContent">暂无评价</p>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-card">
                                <div class="layui-card-header"><i class="fa fa-long-arrow-down icon"></i>最近评分最低客户的评价</div>
                                <div class="layui-card-body">
                                    <div  style="width: 100%;min-height: 140px">
                                        评分：<h1 id="minScore">--</h1>
                                        评价：<p id="minContent">暂无评价</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'layer', 'laydate','echarts'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            echarts = layui.echarts,
            laydate = layui.laydate;

        $('.datetime').each(function () {
            laydate.render({
                elem: this       //使用this指向当前元素,不能使用class名, 否则只有第一个有效
                , type: 'month'
            });
        });
        getData();
        form.on("submit(data-search-btn)",function (data) {
            getData(data);
        });

        function getData(data) {
            if(data!=null) data = data.field;
            $.ajax({
                type:"post",
                data:data,
                url:"evaluationAnalyse/getMaxAndMinEvaluation",
                success:function (result) {
                    //console.log(result.maxEvaluation);
                    /*$("#maxScore").html(result.maxEvaluation.score);
                    $("#maxContent").html(result.maxEvaluation.content);
                   */
                    if(result.maxEvaluation!=null) {
                        $("#maxScore").html(result.maxEvaluation.score);
                        $("#maxContent").html(result.maxEvaluation.content);
                    }else{
                        $("#maxScore").html("无");
                        $("#maxContent").html("无评价");
                    }
                    if(result.minEvaluation!=null){
                        $("#minScore").html(result.minEvaluation.score);
                        $("#minContent").html(result.minEvaluation.content);
                    } else{
                        $("#minScore").html("无");
                        $("#minContent").html("无评价");
                    }
                    //layer.msg("数据加载中",{time:1000});
                }
            });
            $.ajax({
                type:"post",
                data:data,
                url:"evaluationAnalyse/getEvaluationAvg",
                success:function (result) {
                    //console.log(result);
                    $("#companyToCustomer").html(result.companyToCustomer.toFixed(3));
                    $("#customerToCompany").html(result.customerToCompany.toFixed(3));
                    if(result.companyToCustomer == undefined) $("#companyToCustomer").html("无");
                    if(result.customerToCompany == undefined) $("#customerToCompany").html("无");
                }
            });
            $.ajax({
                type:"post",
                data:data,
                url:"evaluationAnalyse/getEvaluationLine",
                success:function (result) {
                    //console.log(result);
                    var xAxisData = [];
                    var evaluationLineData = [];
                    var evaluationLine = result.evaluationLine;
                    for(var i in evaluationLine){
                        xAxisData.push(i);
                        evaluationLineData.push(evaluationLine[i])
                    }
                    myChart.setOption({
                        xAxis: {
                            data: xAxisData
                        },
                        series: [{
                            // 根据名字对应到相应的系列
                            name: '评分数量',
                            data: evaluationLineData
                        }
                        ]
                    });
                }
            });
        }

        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '评分数量'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            /*legend: {
                data: ['评分数量']
            },*/
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                //boundaryGap: false,
                data: ['1', '2', '3', '4', '5', '6', '7','8','9','10']
                //data:xAxisData
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '评分数量',
                    type: 'bar',
                    //tack: '总量',
                    data: [0,0,0,0,170,230,150,110,13,50],
                    //data:increaseData,
                    itemStyle: {
                        color: 'rgb(145,199,174)'
                    }
                }
                /*,{
                    name: '饼状图',
                    type: 'pie',
                    //stack: '总量',
                    data: [10,10,0,10,170,230,150,110,13,50]
                    //data:decreaseData
                }*/
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);

    });
</script>
</body>
</html>
